/*
 * @Description: 地图路线规划 Amap
 * @version: 
 * @Company: 
 * @Author: ZhengZhuang
 * @Date: 2019-08-27 17:38:19
 * @LastEditors: zhengzhuang
 * @LastEditTime: 2020-10-29 17:16:30
 */
import 'dart:async';

import 'package:amap_map_fluttify/amap_map_fluttify.dart';
import 'package:flutter/material.dart';

class RoutePlanningMap extends StatefulWidget {
  @override
  _RoutePlanningMapState createState() => _RoutePlanningMapState();
}

class _RoutePlanningMapState extends State<RoutePlanningMap> {

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    // Timer(Duration(seconds: 2), () {
    //   loading(
    //     context,
    //     AmapSearch().calculateDriveRoute(
    //       RoutePlanParam(
    //         from: LatLng(39.993291, 116.473188),
    //         to: LatLng(39.940474, 116.355426),
    //       ),
    //     ),
    //   ).then((result) {
    //     final allPoint =
    //         result.paths[0].steps.expand((step) => step.polyline).toList();

    //     result.paths[0].steps.expand((step) => step.TMCs).forEach((tmc) {
    //       _controller.addPolyline((PolylineOptions(
    //         latLngList: tmc.polyline,
    //         width: 15,
    //         lineJoinType: PolylineOptions.LINE_JOIN_MITER,
    //         lineCapType: PolylineOptions.LINE_CAP_TYPE_ROUND,
    //         color: _getTmcColor(tmc.status),
    //       )));
    //     });

    //     _controller.zoomToSpan(allPoint);
    //   }).catchError((e) => print('报错报错报错object'));
    // });
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        // Flexible(
        //   child: AMapView(
        //     onAMapViewCreated: (controller) {
        //       setState(() => _controller = controller);
        //     },
        //     amapOptions: AMapOptions(
        //       compassEnabled: false,
        //       zoomControlsEnabled: false,
        //     ),
        //   ),
        // ),
      ],
    );
  }

  Color _getTmcColor(String tmc) {
    switch (tmc) {
      case '未知':
        return Colors.cyan;
      case '畅通':
        return Colors.green;
      case '缓行':
        return Colors.yellow;
      case '拥堵':
        return Colors.red;
      default:
        return Colors.cyan;
    }
  }
}
